<template>
  <div class="story-detail" v-loading="loading">
    <!-- 封面区域 -->
    <div class="cover-section">
      <!-- 添加面包屑 -->
      <div class="breadcrumb-nav">
        <div class="container">
          <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item :to="{ path: '/stories' }"
              >旅行故事</el-breadcrumb-item
            >
            <el-breadcrumb-item>{{ story.title }}</el-breadcrumb-item>
          </el-breadcrumb>
        </div>
      </div>
      <div
        class="cover-image"
        :style="{
          backgroundImage: `url(${utils.getImageUrl(story.coverImage)})`,
        }"
      >
        <div class="cover-overlay">
          <div class="container">
            <div class="story-header">
              <div
                class="category-tag"
                :class="getCategoryClass(story.category)"
              >
                {{ story.category }}
              </div>
              <h1>{{ story.title }}</h1>
              <div class="story-meta">
                <div class="author-info">
                  <el-avatar :size="36" :src="story.author?.avatar || defaultAvatar" />
                  <div class="author-detail">
                    <span class="author-name">{{ story.author?.name }}</span>
                    <span class="publish-time">{{ story.publishDate }}</span>
                  </div>
                </div>
                <div class="story-stats">
                  <span class="stat-item">
                    <el-icon><View /></el-icon>
                    {{ formatNumber(story.stats?.views ?? story.views ?? 0) }}
                  </span>
                  <span class="stat-item">
                    <el-icon><Star /></el-icon>
                    {{ formatNumber(story.stats?.likes ?? story.likes ?? 0) }}
                  </span>
                  <span class="stat-item">
                    <el-icon><ChatRound /></el-icon>
                    {{ formatNumber(totalCommentCount) }}
                  </span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 优化主要内容区域布局 -->
    <div class="main-content">
      <div class="container">
        <el-row :gutter="30">
          <el-col :lg="16" :md="24">
            <!-- 优化文章内容卡片 -->
            <div class="content-card article-content">
              <div class="content-wrapper" v-html="story.content"></div>

              <!-- 添加文章底部操作区 -->
              <div class="article-actions">
                <div class="action-buttons">
                  <el-button :type="isLiked ? 'success' : 'info'" plain @click="handleLike">
                    <el-icon><ThumbUp /></el-icon>
                    {{ isLiked ? '已点赞' : '点赞' }} {{ story.stats?.likes ?? story.likes ?? 0 }}
                  </el-button>
                  <el-button plain @click="scrollToComments">
                    <el-icon><ChatRound /></el-icon>
                    {{ totalCommentCount }} 评论
                  </el-button>
                  <el-button :type="isFavorite ? 'success' : 'info'" plain @click="handleFavorite">
                    <el-icon><StarFilled v-if="isFavorite" /><Star v-else /></el-icon>
                    {{ isFavorite ? '已收藏' : '收藏' }}
                  </el-button>
                </div>
                <div class="share-buttons">
                  <el-button circle><el-icon><Share /></el-icon></el-button>
                </div>
              </div>
            </div>

            <!-- 优化标签区域 -->
            <div class="content-card tags-section">
              <h3 class="section-title">
                <el-icon><Collection /></el-icon>
                文章标签
              </h3>
              <div class="tags-list">
                <el-tag
                  v-for="tag in story.tags"
                  :key="tag"
                  size="large"
                  effect="light"
                  class="tag-item"
                >
                  <el-icon><Pointer /></el-icon>
                  {{ tag }}
                </el-tag>
              </div>
            </div>

            <!-- 优化评论区域 -->
            <div class="content-card comments-section" id="comments">
              <div class="comments-header">
                <h3 class="section-title">评论区</h3>
                <span class="comment-count">
                  {{ totalCommentCount }} 条评论
                </span>
              </div>

              <!-- 添加评论输入框 -->
              <div class="comment-form">
                <el-input
                  v-model="commentContent"
                  type="textarea"
                  :rows="3"
                  placeholder="写下你的想法..."
                />
                <div class="form-footer">
                  <el-button
                    type="primary"
                    :loading="commenting"
                    @click="() => handleReply(commentContent, null)"
                  >
                    发表评论
                  </el-button>
                </div>
              </div>

              <!-- 优化评论列表 -->
              <div class="comments-list">
                <CommentItem
                  v-for="comment in comments"
                  :key="comment.id"
                  :comment="comment"
                  :current-user="currentUser"
                  :on-reply="handleReply"
                  :on-delete="handleDelete"
                />
              </div>
            </div>
          </el-col>

          <!-- 优化侧边栏布局 -->
          <el-col :lg="8" :md="24">
            <div class="sidebar">
              <!-- 作者信息卡片 -->
              <div class="content-card author-card">
                <div class="author-header">
                  <div class="avatar-wrapper">
                    <el-avatar :size="88" :src="story.author?.avatar || defaultAvatar" />
                    <div class="author-badge">
                      <el-icon><Medal /></el-icon>
                      专业领队
                    </div>
                  </div>
                  <div class="author-info">
                    <h3>{{ story.author?.name }}</h3>
                    <p class="author-bio">{{ story.author?.description }}</p>
                    <div class="author-stats">
                      <div class="stat-item">
                        <span class="stat-value">{{
                          story.author?.articles || 0
                        }}</span>
                        <span class="stat-label">文章</span>
                      </div>
                      <div class="stat-divider"></div>
                      <div class="stat-item">
                        <span class="stat-value">{{
                          story.author?.followers || 0
                        }}</span>
                        <span class="stat-label">关注者</span>
                      </div>
                    </div>
                  </div>
                </div>
              </div>

              <!-- 相关故事卡片 -->
              <div class="content-card related-stories">
                <h3 class="section-title">
                  <el-icon><Document /></el-icon>
                  推荐阅读
                </h3>
                <div class="related-list">
                  <div
                    v-if="story.relatedStories?.[0]"
                    class="related-item"
                    @click="viewStory(story.relatedStories[0].id)"
                  >
                    <el-image
                      :src="
                        utils.getImageUrl(story.relatedStories[0].coverImage)
                      "
                      fit="cover"
                      class="related-image"
                    >
                      <template #placeholder>
                        <div class="image-placeholder">
                          <el-icon><Picture /></el-icon>
                        </div>
                      </template>
                    </el-image>
                    <div class="related-info">
                      <h4>{{ story.relatedStories[0].title }}</h4>
                      <p class="related-excerpt">
                        {{ story.relatedStories[0].excerpt }}
                      </p>
                      <div class="related-meta">
                        <div class="meta-left">
                          <el-avatar  :size="24" 
                          :src="story.relatedStories[0] ? getImageUrl(story.relatedStories[0].avatar) : ''" />
          />
                          <span class="author">{{
                            story.relatedStories[0].author?.name ||
                            story.relatedStories[0].authorName ||
                            "未知作者"
                          }}</span>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </el-col>
        </el-row>
      </div>
    </div>
  </div>
</template>
<script setup>
import { ref, onMounted, computed } from "vue";
import { useRoute, useRouter } from "vue-router";
import { formatNumber } from "@/utils/format";
import { ElMessage } from "element-plus";
import {
  Star,
  ChatRound,
  ChatLineRound,
  Share,
  Collection,
  Pointer,
  Medal,
  Plus,
  ChatDotRound,
  Document,
  Picture,
  View,
  UserFilled,
  Calendar,
  Location,
  ArrowRight,
  StarFilled,
  ThumbUp,
} from "@element-plus/icons-vue";
import API from "@/api/index";
import CommentItem from '@/components/CommentItem.vue';
import { getStoryComments, addStoryComment, deleteStoryComment, favoriteStory, unfavoriteStory, isFavoriteStory, likeStory, unlikeStory, isLikedStory } from '@/api/story';

// 创建工具对象，方便在模板中使用
const utils = {
  getImageUrl: (url) => {
    if (!url) return "";
    if (url.startsWith("http")) return url;
    return `${import.meta.env.VITE_API_BASE_URL}${url}`;
  },
  formatDate: (dateString) => {
    if (!dateString) return "";
    const date = new Date(dateString);
    return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(
      2,
      "0"
    )}-${String(date.getDate()).padStart(2, "0")}`;
  },
};

const route = useRoute();
const router = useRouter();
const loading = ref(false);
const liking = ref(false);
const commenting = ref(false);
const story = ref({});
const commentContent = ref("");
const defaultAvatar = "https://tourist-hz.oss-cn-beijing.aliyuncs.com/%E5%A4%B4%E5%83%8F";
const comments = ref([]);
const currentUser = ref(JSON.parse(localStorage.getItem('user')) || { name: '我', avatar: defaultAvatar });
const isFavorite = ref(false);
const isLiked = ref(false);

// 递归统计所有评论（含回复）
function countAllComments(list) {
  let count = 0;
  for (const c of list) {
    count += 1;
    if (c.replies && c.replies.length) {
      count += countAllComments(c.replies);
    }
  }
  return count;
}
const totalCommentCount = computed(() => countAllComments(comments.value));

// 获取故事详情
const fetchStoryDetail = async () => {
  loading.value = true;
  try {
    const id = route.params.id;
    const response = await API.get(`/stories/${id}`);

    if (response.data && response.data.code === 200) {
      story.value = null; // 先清空，强制刷新
      story.value = response.data.data;
      // 兼容 stats 字段
      if (!story.value.stats) {
        story.value.stats = {
          likes: story.value.likes ?? 0,
          comments: (story.value.comments ?? story.value.commentCount ?? 0),
          views: story.value.views ?? 0
        };
      }
      fetchRelatedStories(id);
    } else {
      ElMessage.error(response.data?.msg || "获取故事详情失败");
    }
  } catch (error) {
    console.error("获取故事详情失败:", error);
    ElMessage.error("获取数据失败，请稍后重试");
  } finally {
    loading.value = false;
  }
};

// 获取相关故事
const fetchRelatedStories = async (storyId) => {
  try {
    const response = await API.get(`/stories/${storyId}/related`, {
      params: { size: 4 },
    });

    if (response.data && response.data.code === 200) {
      story.value.relatedStories = response.data.data;
    }
  } catch (error) {
    console.error("获取相关故事失败:", error);
  }
};

// 点赞故事
const handleLike = async () => {
  if (!currentUser.value.id) {
    ElMessage.warning('请先登录后再点赞');
    router.push({ path: '/login', query: { redirect: route.fullPath } });
    return;
  }
  if (isLiked.value) {
    await unlikeStory(route.params.id, currentUser.value.id);
    ElMessage.success('已取消点赞');
    isLiked.value = false;
  } else {
    const res = await likeStory(route.params.id, currentUser.value.id);
    if (res.data && res.data.code === 200) {
      ElMessage.success('点赞成功');
      isLiked.value = true;
    } else {
      ElMessage.warning(res.data?.msg || '已点赞');
    }
  }
};

// 获取评论
const fetchComments = async () => {
  const id = route.params.id;
  comments.value = await getStoryComments(id);
};

// 回复评论
const handleReply = async (content, parentId) => {
  // 未登录跳转到登录页
  if (!currentUser.value || !currentUser.value.id) {
    ElMessage.warning('请先登录后再评论');
    router.push({ path: '/login', query: { redirect: route.fullPath } });
    return;
  }
  const id = route.params.id;
  const data = { content, parentId, userId: currentUser.value.id };
  const res = await addStoryComment(id, data);
  if (res) {
    ElMessage.success(parentId ? '回复成功' : '评论发表成功');
    if (!parentId) commentContent.value = '';
    await fetchComments();
  } else {
    ElMessage.error(parentId ? '回复失败' : '评论发表失败');
  }
};

// 删除评论
const handleDelete = async (commentId) => {
  const userId = currentUser.value.id;
  const ok = await deleteStoryComment(commentId, userId);
  if (ok) {
    ElMessage.success('删除成功');
    await fetchComments();
  } else {
    ElMessage.error('删除失败');
  }
};

// 滚动到评论区
const scrollToComments = () => {
  const commentsElement = document.getElementById("comments");
  if (commentsElement) {
    commentsElement.scrollIntoView({ behavior: "smooth" });
  }
};

// 查看相关故事
const viewStory = (id) => {
  router.push(`/story/${id}`);
};

// 获取分类样式
const getCategoryClass = (category) => {
  const classes = {
    photo: "photo",
    food: "food",
    guide: "guide",
    culture: "culture",
  };
  return classes[category] || "default";
};

// 格式化数字
const formatNum = (num) => {
  return formatNumber(num);
};

// 获取图片URL
const getImageUrl = (url) => {
  return utils.getImageUrl(url);
};

const checkFavorite = async () => {
  if (!currentUser.value.id) {
    isFavorite.value = false;
    return;
  }
  isFavorite.value = await isFavoriteStory(route.params.id, currentUser.value.id);
};

const handleFavorite = async () => {
  if (!currentUser.value.id) {
    ElMessage.warning('请先登录后再收藏');
    router.push({ path: '/login', query: { redirect: route.fullPath } });
    return;
  }
  if (isFavorite.value) {
    await unfavoriteStory(route.params.id, currentUser.value.id);
    ElMessage.success('已取消收藏');
    isFavorite.value = false;
  } else {
    const res = await favoriteStory(route.params.id, currentUser.value.id);
    if (res.data && res.data.code === 200) {
      ElMessage.success('收藏成功');
      isFavorite.value = true;
    } else {
      ElMessage.warning(res.data?.msg || '已收藏');
    }
  }
};

const checkLiked = async () => {
  if (!currentUser.value.id) {
    isLiked.value = false;
    return;
  }
  isLiked.value = await isLikedStory(route.params.id, currentUser.value.id);
};

onMounted(async () => {
  await fetchStoryDetail();
  await fetchComments();
  await checkFavorite();
  await checkLiked();
});
</script>

<style scoped>
.story-detail {
  background: var(--light-bg);
}

.cover-section {
  position: relative;
  height: 70vh;
  min-height: 500px;
}

.breadcrumb-nav {
  position: absolute;
  top: 20px;
  left: 0;
  right: 0;
  z-index: 10;
}

.el-breadcrumb {
  --el-text-color-regular: rgba(255, 255, 255, 0.9);
  --el-text-color-primary: #fff;
  font-size: 0.95rem;
}

.cover-image {
  height: 100%;
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
}

.cover-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.4),
    rgba(0, 0, 0, 0.7)
  );
  display: flex;
  align-items: flex-end;
}

.story-header {
  color: white;
  padding: 60px 0;
  max-width: 800px;
}

.category-tag {
  display: inline-block;
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 0.9rem;
  margin-bottom: 20px;
  backdrop-filter: blur(8px);
}

.story-header h1 {
  font-size: 2.8rem;
  margin: 0 0 30px;
  line-height: 1.3;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.story-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.author-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.author-detail {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.author-name {
  font-size: 1.1rem;
  font-weight: 500;
}

.publish-time {
  font-size: 0.9rem;
  opacity: 0.8;
}

.story-stats {
  display: flex;
  gap: 20px;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.95rem;
}

/* 优化内容区域样式 */
.main-content {
  position: relative;
}

.content-card {
  background: white;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 2px 20px rgba(0, 0, 0, 0.05);
  margin-bottom: 30px;
  transition: all 0.3s ease;
}

.content-card:hover {
  box-shadow: 0 4px 25px rgba(0, 0, 0, 0.08);
}

/* 文章内容样式优化 */
.article-content {
  font-size: 1.1rem;
  line-height: 1.8;
  color: var(--text-color);
}

.article-content :deep(h2) {
  font-size: 1.8rem;
  font-weight: 600;
  margin: 40px 0 20px;
  color: var(--text-color);
}

.article-content :deep(p) {
  margin: 20px 0;
  line-height: 1.8;
}

.article-content :deep(img) {
  max-width: 100%;
  border-radius: 12px;
  margin: 30px 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* 优化文章内容区域样式 */
.content-wrapper {
  font-size: 1.1rem;
  line-height: 1.8;
  color: var(--text-color);
}

.content-wrapper :deep(h2) {
  font-size: 1.8rem;
  font-weight: 600;
  margin: 40px 0 20px;
  color: var(--text-color);
  position: relative;
  padding-left: 16px;
}

.content-wrapper :deep(h2)::before {
  content: "";
  position: absolute;
  left: 0;
  top: 15%;
  height: 70%;
  width: 4px;
  background: var(--primary-color);
  border-radius: 2px;
}

.content-wrapper :deep(p) {
  margin: 20px 0;
  line-height: 1.8;
  text-align: justify;
}

.content-wrapper :deep(img) {
  max-width: 100%;
  height: auto;
  border-radius: 12px;
  margin: 30px 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease;
}

.content-wrapper :deep(img):hover {
  transform: scale(1.02);
}

/* 文章底部操作区 */
.article-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px dashed var(--border-color);
}

.action-buttons {
  display: flex;
  gap: 15px;
}

.action-buttons .el-button {
  padding: 12px 24px;
  font-size: 1rem;
}

.share-buttons {
  display: flex;
  gap: 10px;
}

/* 标签区域样式优化 */
.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.4rem;
  margin-bottom: 20px;
  color: var(--text-color);
}

.section-title .el-icon {
  font-size: 1.2em;
  color: var(--primary-color);
}

.tags-list {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.tag-item {
  padding: 8px 16px;
  font-size: 0.95rem;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.tag-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.tag-item .el-icon {
  font-size: 0.9em;
}

/* 评论区优化 */
.comments-section {
  scroll-margin-top: var(--header-height);
}

.comment-form {
  margin-bottom: 40px;
  padding: 25px;
  background: var(--light-bg);
  border-radius: 12px;
  transition: all 0.3s ease;
}

.comment-form:focus-within {
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

.form-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
}

/* 响应式优化 */
@media (max-width: 768px) {
  .content-wrapper {
    font-size: 1rem;
  }

  .content-wrapper :deep(h2) {
    font-size: 1.5rem;
    margin: 30px 0 15px;
  }

  .article-actions {
    flex-direction: column;
    gap: 15px;
  }

  .action-buttons {
    width: 100%;
    justify-content: center;
  }

  .share-buttons {
    width: 100%;
    justify-content: center;
  }

  .tag-item {
    padding: 6px 12px;
    font-size: 0.9rem;
  }
}

/* 标签区域样式优化 */
.section-title {
  font-size: 1.4rem;
  font-weight: 600;
  margin-bottom: 20px;
  color: var(--text-color);
}

.tags-list {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.tag-item {
  padding: 8px 16px;
  font-size: 0.95rem;
  border-radius: 20px;
  transition: all 0.3s ease;
}

.tag-item:hover {
  transform: translateY(-2px);
}

/* 评论区样式优化 */
.comments-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
}

.comment-count {
  color: var(--text-color-secondary);
  font-size: 0.95rem;
}

.comment-form {
  margin-bottom: 40px;
  padding: 20px;
  background: var(--light-bg);
  border-radius: 12px;
}

.form-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
}

.comments-list {
  display: flex;
  flex-direction: column;
  gap: 25px;
}

.comment-item {
  display: flex;
  gap: 20px;
  padding: 20px;
  border-radius: 12px;
  background: var(--light-bg);
  transition: all 0.3s ease;
}

.comment-item:hover {
  transform: translateX(5px);
  background: white;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
}

.comment-content {
  flex: 1;
}

.comment-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
}

.comment-author {
  font-weight: 500;
  color: var(--text-color);
}

.comment-time {
  font-size: 0.9rem;
  color: var(--text-color-secondary);
}

.comment-text {
  margin: 0 0 15px;
  line-height: 1.6;
  color: var(--text-color);
}

.comment-actions {
  display: flex;
  gap: 20px;
}

/* 侧边栏样式优化 */
.sidebar {
  position: sticky;
  top: calc(var(--header-height) + 20px);
  transition: all 0.3s ease;
}

/* 作者卡片样式优化 */
.author-card {
  text-align: center;
  padding: 20px;
  border: 1px solid var(--border-color);
  background: linear-gradient(to bottom, white, var(--light-bg));
}

.avatar-wrapper {
  position: relative;
  display: inline-block;
  margin-bottom: 20px;
}

.author-badge {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary-color);
  color: white;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.author-info h3 {
  font-size: 1.4rem;
  margin: 0 0 10px;
  background: linear-gradient(45deg, var(--primary-color), #36cfc9);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.author-bio {
  color: var(--text-color-secondary);
  line-height: 1.6;
  font-size: 0.95rem;
}

.author-stats {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 30px;
  margin: 20px 0;
}

.stat-divider {
  width: 1px;
  height: 20px;
  background: var(--border-color);
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--text-color);
  line-height: 1;
}

.stat-label {
  font-size: 0.9rem;
  color: var(--text-color-secondary);
}

.author-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.follow-button {
  height: 40px;
  border-radius: 20px;
  font-weight: 500;
}

.message-button {
  height: 40px;
  border-radius: 20px;
  border: 1px dashed var(--border-color);
  color: var(--text-color);
  background: transparent;
}

.message-button:hover {
  color: var(--primary-color);
  border-color: var(--primary-color);
  background: var(--light-bg);
}

/* 相关故事卡片样式优化 */
.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.2rem;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px dashed var(--border-color);
}

.section-title .el-icon {
  color: var(--primary-color);
  font-size: 1.3em;
}

.related-list {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.related-item {
  display: flex;
  gap: 15px;
  padding: 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.related-item:hover {
  background: var(--light-bg);
  transform: translateX(5px);
}

.related-image {
  width: 120px;
  height: 80px;
  border-radius: 8px;
  overflow: hidden;
}

.image-placeholder {
  width: 100%;
  height: 100%;
  background: var(--light-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-color-secondary);
}

.related-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.related-info h4 {
  font-size: 1rem;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: var(--text-color);
}

.related-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}

.meta-left {
  display: flex;
  align-items: center;
  gap: 6px;
}

.meta-left .author {
  font-size: 0.9rem;
  color: var(--text-color-secondary);
}

.meta-right {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--text-color-secondary);
  font-size: 0.85rem;
}

/* 响应式优化 */
@media (max-width: 992px) {
  .sidebar {
    position: static;
    margin-top: 30px;
  }

  .related-item {
    padding: 10px;
  }

  .related-image {
    width: 100px;
    height: 70px;
  }
}

@media (max-width: 768px) {
  .cover-section {
    height: 60vh;
    min-height: 400px;
  }

  .story-header h1 {
    font-size: 2rem;
  }

  .story-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 15px;
  }

  .main-content {
    margin-top: -40px;
  }

  .content-card {
    padding: 20px;
  }

  .sidebar {
    position: static;
    margin-top: 30px;
  }

  .author-card {
    margin-top: 30px;
  }

  .comment-item {
    padding: 15px;
  }

  .related-item {
    padding: 10px;
  }

  .related-image {
    width: 80px;
    height: 60px;
  }
}

/* 相关故事样式优化 */
.related-stories {
  margin-top: 20px;
}

.related-item {
  display: flex;
  flex-direction: column;
  gap: 15px;
  padding: 15px;
  border-radius: 12px;
  cursor: pointer;
  background: var(--light-bg);
  transition: all 0.3s ease;
}

.related-item:hover {
  transform: translateY(-5px);
  background: white;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.related-image {
  width: 100%;
  height: 160px;
  border-radius: 8px;
  overflow: hidden;
}

.related-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.related-info h4 {
  font-size: 1.1rem;
  margin: 0;
  color: var(--text-color);
  line-height: 1.4;
}

.related-excerpt {
  font-size: 0.95rem;
  color: var(--text-color-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 0;
  line-height: 1.6;
}

.meta-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.meta-left .author {
  font-size: 0.95rem;
  color: var(--text-color-secondary);
}
</style>
